import { sgsEvent } from '/src/core/event';
import { Store } from "./../../model/Store";
import { Player } from "./../../model/Player";
import { GameOptions } from ".";

export enum GameStatus {
    normal,
    over,
    error,
    stop
}

export class GameController {
	constructor(
		private players: Player[],
		private store: Store,
		private options: GameOptions
    ) {
        
    }
    
    private get gameStatusController() {
        return {
            state: (() => {
				let status = GameStatus.normal;
				return function(setStatus?: GameStatus){
					if (setStatus === undefined) return status;					
					return status = setStatus;
				};
            })(),
            throwError() {
                this.state(GameStatus.error)
            }
        }
    }

	private get playerOrderController() {
		return {
			order: (() => {
				let index = 0;
				return function(setIndex?: number){
					if (setIndex === undefined) return index;					
					return index = setIndex;
				};
			})(),

			next: () => {
				const index = this.playerOrderController.order();
				return this.playerOrderController.order(
					(index + 1) % this.options.player.count
				);
			}
		};
    }
    
    private playerRoundStart(id: number) {
        const currentPlayer = this.players[id];
        currentPlayer.getCards(2);
    }
}
